
limit = 4*1e6
prev = [1,2]
def fibonacci(limit):
    prev = [1,2]
    yield prev[0]
    yield prev[1]
    while 1:
        re = prev[0] + prev[1]
        if re > limit: 
            return
        yield re
        prev[::] = [prev[1], re]
res = sum([ i for i in fibonacci(limit) if i % 2 == 0])
print 'the result is:',res
